<template>
    <h2>添加借款信息</h2>
    <table class="table table-bordered">
        <tr>
            <td>借款名称</td>
            <td><input type="text" v-model="info.BM_Name"></td>
        </tr>
        <tr>
            <td>借款最高年限</td>
            <td><input type="text" v-model="info.BM_Year"></td>
        </tr>
        <tr>
            <td>借款最高额度</td>
            <td><input type="text" v-model="info.Mb_Money"></td>
        </tr>
        <tr>
            <td>借款介绍</td>
            <td><input type="text" v-model="info.BM_Info"></td>
            
        </tr>
        <tr>
            <td>借款利息</td>
            <td>
                <select v-model="info.BMI_Id">
                    <option value="0">--请选择--</option>
                    <option v-for="item in bind" :value="item.BMI_Id">{{ item.BMI_Year }}年利息{{ item.BMI_Interest }}%</option> 
                </select>
            </td>
        </tr>
        <tr>
            <td>
                <input type="button" value="提交" @click="addInfo" >
            </td>
        </tr>
        
    </table>
</template>
<script setup lang="ts">
import { ref,onMounted } from 'vue';
import { useRouter } from 'vue-router';
import axios from 'axios';

const router = useRouter();

onMounted(() => {
    bindInfo();
})

const bind = ref({
    BMI_Id:0,
    BMI_Year:0,
    BMI_Interest:0
})

const bindInfo = () => {
    axios.get('http://localhost:58004/api/Borrow/Bind'
    , bind.value)
    .then(res => {
        bind.value = res.data;
        console.log(bind.value);
    })
    
    .catch(err => {
        console.log(err);
    })
}




const info = ref({
    BM_Name: '',
    BM_Year: '',
    Mb_Money: '',
    BM_Info: '',
    BMI_Id:0,
})

const addInfo = () => {
    axios.post('http://localhost:58004/api/Borrow/Add'
    , info.value)
    .then(res => {
        if(res.data>0){
            alert('添加成功');
            router.push('/ShowBorrow');
        }else{
            alert('添加失败');
        }
    })
    .catch(err => {
        console.log(err);
    })
}
</script>